package ch.zhaw.cctd.domain.tower;

import java.awt.Point;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.zhaw.cctd.domain.Shootable;
import ch.zhaw.cctd.domain.Shooter;
import ch.zhaw.cctd.domain.map.Map;

/**
 * Zuständig die Art des Treffers zu errechen, wenn der Schuss einschlägt. Trifft mehrere Creeps auf einmal
 * @author Rolf Koch
 * @author Benjamin Felder
 */
public class SplashTowerEffect extends TowerEffect {

	private static final long serialVersionUID = -6157575421320860197L;
	private static final Logger logger = LoggerFactory.getLogger(SplashTowerEffect.class);

	public SplashTowerEffect(Integer range) {
		super(TowerEffectType.SPLASH, range);
	}
	
	@Override
	public void hitEffect(Point hitpoint, Shooter t, Shootable c, Map map) {
		for (Shootable creep : map.getShootableList()) {
			if ((hitpoint.distance(creep.getCenter())) <= this.value) {
				logger.trace("splash damage to shootable {}", creep);
				if (creep.damage(t.getDamage()) <= 0) { // dies
					t.incStatsKill();
					t.getOwner().receiveRessource(creep.payCreepMoney());
					logger.trace("splash kill: get money");
				}
			}
		}
	}
}